/*
 *  Copyright (C) 2010 Alexander Chernykh 
 *
 *  This file is part of MyQuik: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  MyQuik is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *
 *  common.h
 */

#pragma once

#include "types.h"
#include <str.h>

enum {
	HIDE = 1,
};

enum {
	GET = 0,
	SET = 1,
};

enum {
	NUPDATE = 0,
	UPDATE = 1,
};

enum {
	OP_SELL,
	OP_BUY,
	OP_UNKNOWN,
};

enum {
	APPLY_SETTINGS_COMMON = 0x01,
	APPLY_SETTINGS_LOG = 0x02,
	APPLY_SETTINGS_SERVER = 0x04,
	APPLY_SETTINGS_TRADING = 0x08,
	APPLY_SETTINGS_INSTRUMENT = 0x10,
	APPLY_SETTINGS_KEYS = 0x20,
	APPLY_SETTINGS_PRESENTATION_MAIN = 0x100,
	APPLY_SETTINGS_PRESENTATION_LIST = 0x200,
	APPLY_SETTINGS_PRESENTATION_OSD = 0x400,
	APPLY_SETTINGS_PRESENTATION_GLASS = 0x800,
};

enum {
	F_FORCE = 0x8000,
};

enum {
	F_SHOW_MENU = 0x0,
	F_GET_MENU = 0x1,
	F_GET_MENU_TRADE = 0x2,
	F_GET_MENU_INSTRUMENTS = 0x4,
	F_GET_MENU_SHOW = 0x8,
	F_GET_MENU_MAIN = (F_GET_MENU_TRADE|F_GET_MENU_INSTRUMENTS|F_GET_MENU_SHOW),
};


enum {
	I_ICON_SENT,
	I_ICON_CANCEL,
	I_ICON_BUY,
	I_ICON_SELL,
	I_ICON_ACTIVE_BUY,
	I_ICON_ACTIVE_SELL,
	I_ICON_CANCEL_BUY,
	I_ICON_CANCEL_SELL,
	I_ICON_STOP_BUY,
	I_ICON_STOP_SELL,
	I_ICON_ACTIVE_STOP_BUY,
	I_ICON_ACTIVE_STOP_SELL,
	I_ICON_CANCEL_STOP,
	I_ICON_CANCEL_STOP_BUY,
	I_ICON_CANCEL_STOP_SELL,
	I_ICON_BUY_GRAY,
	I_ICON_SELL_GRAY,
	I_ICON_STOP_BUY_GRAY,
	I_ICON_STOP_SELL_GRAY,
	I_ICON_LAST,
};

enum {
	COL_NULL,
	COL_INDEX,
	COL_ICON,
	COL_NUMBER,
	COL_DATE,
	COL_TIME,
	COL_NAME,
	COL_SECCODE,
	COL_CLASS,
	COL_OPERATION,
	COL_PRICE,
	COL_PRICE2,
	COL_QUANTITY,
	COL_VOLUME,
	COL_STATUS,
	COL_CLIENT,
	COL_ACCOUNT,
	COL_LAST,
};

enum {
	COL_FIRST = COL_INDEX,
};

enum {
	I_COLOR_NORMAL,
	I_COLOR_BUY,
	I_COLOR_SELL,
	I_COLOR_ACTIVE_BID_BUY,
	I_COLOR_ACTIVE_BID_SELL,
	I_COLOR_ACTIVE_STOP_BUY,
	I_COLOR_ACTIVE_STOP_SELL,
	I_COLOR_EXECUTED_STOP_BUY,
	I_COLOR_EXECUTED_STOP_SELL,
	I_COLOR_CANCELED_BID_BUY,
	I_COLOR_CANCELED_BID_SELL,
	I_COLOR_CANCELED_STOP_BUY,
	I_COLOR_CANCELED_STOP_SELL,
	I_COLOR_FAILED_BUY,
	I_COLOR_FAILED_SELL,
	I_COLOR_FRAME,
	I_COLOR_INDEX,
	I_COLOR_LAST,
};

#define NR_LIST_COLORS_MAX I_COLOR_LAST

#define NR_COLS_MAX COL_LAST

enum Sorting {
	SORT_BY_ZERO = 0x00,
	SORT_BY_TIME = 0x01,
	SORT_BY_DATE = 0x02,
	SORT_BY_NUMBER = 0x04,
	SORT_BY_PRICE = 0x08,
	SORT_BY_QUANTITY = 0x10,
	SORT_BY_VOLUME = 0x20,
	SORT_BY_STATUS = 0x40,
	SORT_BY_SECCODE = 0x80,
	SORT_BY_OPERATION = 0x100,
	SORT_BY_ICON = 0x200,
	SORT_BY_NAME = 0x800,
	SORT_BY_CLASSCODE = 0x1000,
	SORT_BY_CLIENTCODE = 0x2000,
	SORT_BY_ACCOUNT = 0x4000,
	SORT_BY_PRICE2 = 0x8000,
	SORT_BY_DATE_AND_TIME = (SORT_BY_DATE|SORT_BY_TIME),
};

struct TxtFormat {
	CHARFORMAT cf;	
	SIZE offset;
	struct Placement {
		int vertical; 
	} placement;
	BOOL groupDigits;
};

enum {
	TIMER_CONNECTION,
	TIMER_OSD,
};


enum {
	OSD_NORMAL_TEXT = 0x01,
	OSD_PRICE_CURRENT = 0x02,
	OSD_PRICE_MAXIMUM = 0x04,
	OSD_PRICE_MINIMUM = 0x08,
	OSD_PERCENT = 0x10,
	OSD_INDICATOR_PRICE = 0x20,
	OSD_INDICATOR_DEMANDSUPPLY = 0x40,
	OSD_LIMIT = 0x80,
	OSD_PROFIT = 0x100,
	OSD_TRADE_PRICE = 0x200,
	OSD_TRADE_PROFIT = 0x400,
	OSD_TRADE_LAST = 0x800,
	OSD_INFO_TRANSACTIONS = 0x1000,
	OSD_INFO_INSTRUMENT_NAME = 0x2000,
	OSD_INFO_INSTRUMENT_CODE = 0x4000,
};

enum {
	GLASS_STYLE_1,
	GLASS_STYLE_2,
	GLASS_STYLE_3,
};

enum {	
	GLASS_ITEM_COMMON,
	GLASS_ITEM_BUY,
	GLASS_ITEM_SELL,
	GLASS_ITEM_BUY_PRICE,
	GLASS_ITEM_BUY_VOLUME,
	GLASS_ITEM_BUY_USER,
	GLASS_ITEM_SELL_PRICE,
	GLASS_ITEM_SELL_VOLUME,
	GLASS_ITEM_SELL_USER,
	GLASS_ITEM_NEUTRAL_ZONE,
	GLASS_ITEM_NEUTRAL_PRICE,
	GLASS_ITEM_NEUTRAL_VOLUME,
	GLASS_ITEM_NEUTRAL_USER,
	GLASS_ITEM_USER,
	GLASS_ITEM_USER_BIDS_BUY,
	GLASS_ITEM_USER_BIDS_SELL,
	GLASS_ITEM_USER_STOPS_BUY,
	GLASS_ITEM_USER_STOPS_SELL,
	GLASS_ITEM_USER_DEALS_BUY,
	GLASS_ITEM_USER_DEALS_SELL,	
	GLASS_ITEM_PRICE_MIN,
	GLASS_ITEM_PRICE_MAX,
	GLASS_ITEM_PRICE_LAST,
	GLASS_ITEM_PRICE_BID,
	GLASS_ITEM_PRICE_OFFER,
	GLASS_ITEM_COLUMNS,
	GLASS_ITEM_GRID,
	GLASS_ITEM_BORDER,
	GLASS_ITEM_MARKER,
	GLASS_ITEM_VIEW,
	GLASS_ITEM_LAST,
};

enum {
	I_OUTLINE_NORMAL,
	I_OUTLINE_ITALIC,
	I_OUTLINE_BOLD,
	I_OUTLINE_BOLDNITALIC,
};

enum {
	ALIGNMENT_LEFT,
	ALIGNMENT_RIGHT,
	ALIGNMENT_CENTER,
};

enum {
	SPACING_TOP,
	SPACING_BOTTOM,
	SPACING_LEFT,
	SPACING_RIGHT,
};

enum {
	GRID_LINES_VERTICAL = 0x1,
	GRID_LINES_HORIZONTAL = 0x2,
	GRID_LINES_ALL = (GRID_LINES_VERTICAL|GRID_LINES_HORIZONTAL),
	GRID_LINES_NOTHING = 0x0,
};

enum {
	BORDER_LINES_BORDERS = 0x1,
	BORDER_LINES_MEDIAN = 0x2,
	BORDER_LINES_ALL = (BORDER_LINES_BORDERS|BORDER_LINES_MEDIAN),
};

enum {
	MARKER_FOLLOW_PRICE = 0x1,
	MARKER_FOLLOW_CURSOR = 0x2,
	MARKER_FOLLOW_MENU = 0x4,
};


enum {
	I_WINDOW_DEALS,
	I_WINDOW_GLASS,
	I_WINDOW_HISTORY,
	I_WINDOW_LOG,
	I_WINDOW_STOP,
	I_WINDOW_LAST,
};

enum {
	F_SHOW_WINDOW = 0x01,
	F_SHOW_TITLE = 0x02,
	F_SHOW_FRAME = 0x04,
};

enum {
	F_VIEW_ALLWAYS_ON_TOP = 0x01,
	F_VIEW_ENABLE_FLASHING = 0x02,
};

enum {
	F_MAIN_SHOW_LIST = 0x1,
	F_MAIN_SHOW_OSD = 0x2,
	F_MAIN_SHOW_CONTROLS = 0x4,
};

enum {
	F_GLASS_VIEW_BUY_UP = 0x01,
	F_GLASS_VIEW_FLIP_HORIZONTAL = 0x02,
	F_GLASS_VIEW_RAREFIED = 0x04,
	F_GLASS_VIEW_NEUTRAL_ZONE = 0x08,
};

enum {
	F_USER_SHOW_ACTIVE_BIDS = 0x01,
	F_USER_SHOW_ACTIVE_STOPS = 0x02,
	F_USER_SHOW_ACTIVE_DEALS = 0x04,
	F_USER_SHOW_ICONS = 0x08,
	F_USER_SHOW_USER_COLUMN = 0x10,
	F_USER_GROUP_BY_PRICE = 0x80,
};

enum {
	F_TRADING_PRINT_MESSAGE_ON_TRANSACTION_ERROR = 0x1,
	F_TRADING_CANCEL_ALL = 0x10,
};

#define DEFAULT_COLOR_BUY RGB(255, 190, 180)
#define DEFAULT_COLOR_SELL RGB(190, 255, 180)
#define DEFAULT_COLOR_BUY_TEXT RGB(128, 0, 0)
#define DEFAULT_COLOR_SELL_TEXT RGB(0, 96, 0)
#define DEFAULT_COLOR_FILL RGB(255, 255, 255)
#define DEFAULT_COLOR_GRID RGB(150, 150, 150)
#define DEFAULT_COLOR_BORDER RGB(0, 0, 255)
#define DEFAULT_COLOR_MARKER RGB(45, 45, 45)
#define DEFAULT_COLOR_TEXT RGB(0, 0, 0)
#define DEFAULT_COLOR_USER RGB(0, 0, 0)
#define DEFAULT_COLOR_USER_BACKGROUND RGB(233, 233, 255)

enum {
	I_LAYOUT_DEFAULT,
	I_LAYOUT_CUSTOM,
};

enum {
	MMENU_TRADING,
	MMENU_INSTRUMENTS,
	MMENU_SHOW,
};

enum {
	LOAD_TRADE_RUN,
	LOAD_TRADE_DONE,
	LOAD_TRADE_ON_BEGIN,
	LOAD_TRADE_ON_END,
};

enum {
	CODE_OK = 0,
	CODE_ERROR = -1,
	CODE_USER_ERROR = -2,
	CODE_USER_WARNING = -3,
	CODE_USER_INFORMATION = -4,
};

extern int FormatString(LPTSTR str, size_t size, double d, int n);
extern double Mul_0_1(double d, int n);
extern int CalculateLengthAfterPoint(LPCTSTR str, int length);

enum {
	F_VALID_COLOR_HIGHLIGHT = 0x1,
};
extern void GetHighlightParams(HWND hWnd, COLORREF & highlight, COLORREF & inactive, COLORREF & active, double & opacity, int flags = 0);

BOOL IsModernOS(DWORD * pMajor = NULL, DWORD * pMinor = NULL);

namespace my {
	int MessageBox(HWND hWnd, LPCTSTR text, UINT uType = MB_OK);

	namespace ctrl {
		int GetFocusedItem(const CListViewCtrl & list, int iItem = -1, int flags = LVNI_ALL|LVNI_FOCUSED);
		int SetFocusedItem(CListViewCtrl & list, int iItem, int flags = LVNI_FOCUSED);
	} // namespace ctrl

} // namespace my


#if defined _DEBUG && 1
DWORD SetTicks1();
DWORD SetTicks2();
DWORD GetTicks1();
DWORD GetTicks2();
DWORD GetTicksDelta();
#endif
